package tools.IT;

public class operation {

	public static int wordValue(String word)throws Exception{
		return wordValue(word,standard.getAlphabet());
	}
	/**
	 * 
	 * @param word
	 * @param alphabet
	 * @return integer value of the word according to the alphabet used
	 * @throws IndexOutOfBoundsException when the word contains a character not present in the alphabet
	 */
	public static int wordValue(String word,char[] alphabet)throws IndexOutOfBoundsException{
		int value=0;
		for(int i=word.length()-1,j=1;i>=0;i--,j*=alphabet.length)
			for(int k=0;word.charAt(i)!=alphabet[k];k++)
				value+=j;
		return value;
	}
	public static int characterValue(char c)throws Exception{
		return characterValue(c,standard.getAlphabet());
	}
	public static int characterValue(char c, char[] alphabet)throws Exception{
		int value=0;
		for(;alphabet[value]!=c;value++);
		return value;
	}
}
